//
//  HomeTableViewController.m
//  CD1505Weibo
//
//  Created by HeHui on 15/12/29.
//  Copyright (c) 2015年 Hawie. All rights reserved.
//

#import "HomeTableViewController.h"
#import "UIBarButtonItem+Util.h"
#import "TitleButton.h"
#import "DropControl.h"
@interface HomeTableViewController ()
@property(nonatomic,strong)DropControl*dropControl;
@end

@implementation HomeTableViewController

-(DropControl *)dropControl
{
    if (_dropControl==nil) {
        _dropControl=[[DropControl alloc]initWithInsideViewFrame:CGRectMake(100, 60, 300, 300) inView:self.tabBarController.view];
        __weak typeof (self)weakSelf=self;
        _dropControl.afhblk=^{
            TitleButton*btn=(TitleButton*)weakSelf.navigationItem.title;
            if (btn.selected) {
                btn.selected=NO;
            }
        };
    }
    return _dropControl;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self createNaviBarItem];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
-(void)createNaviBarItem
{
//    UIButton*leftButton=[UIButton buttonWithType:UIButtonTypeCustom];
//    
//    [leftButton setImage:[UIImage imageNamed:@"navigationbar_friendattention"] forState:UIControlStateNormal];
//    [leftButton setImage:[UIImage imageNamed:@"navigationbar_friendattention_highlighted"] forState:UIControlStateHighlighted];
//    CGSize size=leftButton.currentImage.size;
//    leftButton.frame=CGRectMake(0, 0, size.width, size.height);
//    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:leftButton];
     self.navigationItem.leftBarButtonItem=[UIBarButtonItem generateBarButtonItemWithNormaImageName:@"navigationbar_friendattention"  gighlightedImageName:@"navigationbar_friendattention_highlighted"];
    self.navigationItem.rightBarButtonItem=[UIBarButtonItem generateBarButtonItemWithNormaImageName:@"navigationbar_icon_radar"  gighlightedImageName:@"navigationbar_icon_radar_highlighted"];
    TitleButton*btn=[TitleButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:@"1213" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"navigationbar_arrow_down"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"navigationbar_arrow_up"] forState:UIControlStateSelected];
    btn.frame=CGRectMake(0, 0, 200, 30);
    btn.backgroundColor=[UIColor clearColor];
    
    self.navigationItem.titleView=btn;
    [btn addTarget:self action:@selector(titleBtnPressed:) forControlEvents:UIControlEventTouchDown];
    
}
-(void)titleBtnPressed:(TitleButton*)btn
{
    btn.selected=!btn.selected;
    if (btn.selected) {
        [self.dropControl show];
    }
    else
    {
        [self.dropControl dismiss];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 0;
}

/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
